<template>
    <div>
        <mHeader></mHeader>
        <div class="main-con">
            <div class="left_main">
                <leftMenu />
            </div>
            <div class="rightMain">
                <!-- 用户 -->
                <div class="list_box" v-for="(item, index) in list" :key="index" @click="goPage(item.type, item.id)">
                    <img :src="item.avatar" alt="">
                    <div class="list_t">
                        <span class="line2">{{ item.title }}</span>
                        <div>
                            <span class="line1">{{ item.user_nickname }}</span>
                            <!-- <span v-if="(index % 3 - 1) != 0" class="line1">主委昵称</span> -->
                            <!-- <div v-else class="line1 resou">
                                摘自<span>【金庸全集】</span>
                            </div> -->
                            <div class="eye">
                                <img src="@/assets/img/eye.png" alt="">
                                <span>{{ item.views }}</span>
                            </div>
                        </div>
                    </div>

                </div>
                <div style="display: flex;justify-content: center;">
                    <el-empty description="没有内容了" v-if="list.length == 0" :image-size="$store.getters.isMobile?150:300"></el-empty>
                </div>
            </div>


        </div>


    </div>
</template>
<script>
import leftMenu from '@/components/leftMenu.vue';
export default {
    components: {
        leftMenu
    },
    data() {
        return {
            menuList: [],
            loading: false,
            totalPage: 1,
            pageNum: 1,
            list: [],
            total: 0

        };
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件
        this.getList()

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },
    methods: {
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
            }

            this.$api.getMyFirends(params).then(res => {
                if (res.data.code == 1) {
                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
        load() {
            console.log('触底了');
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        getTabtype(t, url) {
            this.curType = t
            if (this.path != url) this.$router.push(url)

        },
        onSubmit() {
            console.log('submit!', this.form);
        },
        goPage(type, id) {
            let url = '/columnRead'
            if (type == 'col') {
                this.$router.push({
                    path: url,
                    query: {
                        id
                    }
                })
            }


            if (type == 'art') {
                let aid = id
                this.$router.push({
                    path: url,
                    query: {
                        aid
                    }
                })
            }
        },
    },
}
</script>
<style lang="scss" scoped>
.main-con {
    display: flex;

    .left_main {
        margin-right: 1.04rem;
    }
}

.rightMain {
    border-top: 0.05rem solid #E8E8E8;
    padding-top: 20px;
    flex: 1;

    .list_box {
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        width: calc(33% - 18px);
        height: 130px;
        border: 1px solid #C3DCFB;
        padding: 1.04rem 1.6rem 0.94rem 0.99rem;
        margin: 10px 0;

        &:nth-child(3n-1) {
            margin: 10px 33px;
        }

        >img {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .list_t {
            flex: 1;

            margin-left: 0.99rem;
            display: flex;
            justify-content: space-between;
            flex-direction: column;
            height: 100%;

            >span {
                font-weight: 400;
                font-size: 22px;
                color: #000000;
            }

            >div {
                display: flex;

                align-items: center;
                justify-content: space-between;

                >span {
                    font-weight: 400;
                    font-size: 18px;
                    color: #999999;
                }

                .resou {
                    font-weight: 400;
                    font-size: 18px;
                    color: #999999;

                    >span {
                        color: #1068E7;
                    }
                }

                .eye {
                    font-weight: 400;
                    font-size: 18px;
                    color: #999999;
                    flex-shrink: 0;
                    display: flex;
                    align-items: center;

                    img {
                        width: 23px;
                        height: 16px;
                        margin-right: 0.3rem;
                    }
                }
            }
        }

        .list_t2 {
            margin-left: 0.99rem;
            display: flex;
            justify-content: space-between;
            flex-direction: column;
            height: 100%;
            width: 14.27rem;

            .name {
                display: flex;
                align-items: center;
                font-weight: 400;
                font-size: 1.15rem;
                color: #333333;

                img {
                    width: 1.25rem;
                    height: 1.25rem;
                    margin-left: 0.7rem;
                    flex-shrink: 0;
                }
            }

            .vip {
                color: #1068E7;
            }

            .sign {
                width: 100%;
                font-weight: 400;
                font-size: 1.04rem;
                color: #666666;
            }

            .hot {
                display: flex;
                align-items: center;
                margin-top: 0.5rem;

                div {
                    display: flex;
                    align-items: center;
                    font-weight: 400;
                    font-size: 0.94rem;
                    color: #999999;
                    margin-right: 1.6rem;

                    img {
                        width: 1.2rem;
                        height: 1.09rem;
                    }

                    &:nth-child(2) {
                        img {
                            width: 0.99rem;
                            height: 0.99rem;
                        }
                    }
                }
            }
        }
    }
}
@media screen and (max-width:768px) {
    .left_main{
        display: none;
    }
    .main-con {
        width: 100%;
        padding: 0 10px;
    }
    .rightMain  {
                            .list_box {
                                margin: 0 0 10px !important;
                                padding: 10px;
                                width: 100%;
                                height: 100px;
                                >img {
                                    width: 70px;
                                    height: 70px;
                                }

                                .list_t {
                                    margin-left: 15px;

                                    >span {
                                        font-size: 16px;
                                    }

                                    >div {
                                        >span {
                                            font-size: 16px;
                                        }

                                      .eye{
                                            font-size: 13px;

                                            img {
                                                width: 15px;
                                                height: 9px;
                                                margin-right: 5px;
                                            }
                                        }
                                    }
                                }

                            }
                        }
}
</style>